<#import 'common.ftl' as com>
<@com.page title='发布文章'>
    <h1 class="text-center">文章发布</h1>
    <form class="container" style="padding-top: 100px">
        <div class="form-group">
            <label for="name">标题</label>
            <div style="display: flex;flex-direction: row">
                <input id="title" type="text" class="form-control" placeholder="请输入标题">
                <label   style="color: red;padding-left: 0;white-space: nowrap;height: 30px;line-height: 30px;padding-bottom: 0px">(*必填)</label>
            </div>

        </div>
        <div class="form-group">
            <label for="content">内容</label>
            <div style="display: flex;flex-direction: row">
                <textarea id="content" class="form-control" rows="4" placeholder="请输入内容"></textarea>
                <label  style="color: red;padding-left: 0;white-space: nowrap;height: 30px;line-height: 30px;padding-bottom: 0px;visibility: hidden">(*必填)</label>
            </div>

        </div>
        <div class="form-group">
            <button class="btn btn-primary center-block" type="button">发布</button>
        </div>
    </form>
    <#--<iframe style="margin-left: 10%;" width="80%" src="/login" height="1000px" frameborder=0 ></iframe>-->
</@com.page>

<script>
    $(document).ready(()=>{
        console.log(JSON.stringify('${user.getId()}') )
        $('button.btn').click(()=>{

            var title=$("#title").val()
            if (!title){
                alert('标题不能为空')
            }
            else
            {
                jsJson().postrequest('/publisharticles',{
                    title:title,
                    content:$("#content").val(),
                    user_id:parseInt('${user.id}')
                },callBack=>{
                    if(callBack.code==200){
                        window.location.href='./home'
                    }
                    else
                    {
                        alert(callBack.mes)
                    }
                })
            }
        })
    })
</script>